/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    int findSecondMinimumValue(TreeNode* root) {
        if(root==nullptr){return -1;}
        priority_queue<int,vector<int>,greater<int>>ans;
        TreeNode* tmp;
        queue<TreeNode*>que;
        que.push(root);
        ans.push(root->val);
        while(!que.empty()){
            tmp=que.front();
            que.pop();
            if(tmp->left!=nullptr){
                que.push(tmp->left);
                if(tmp->left->val>ans.top()){ans.push(tmp->left->val);}    
            }
            if(tmp->right!=nullptr){
                que.push(tmp->right);
                if(tmp->right->val>ans.top()){ans.push(tmp->right->val);}    
            }
        }
        if(ans.size()==1){return -1;}
        ans.pop();
        return ans.top();
    }
};